package org.hawk.gwt.ppc.parser;

/**
 * Java language token. Hides one or several characters within.
 * In conservative term represents modifiable characters sequence.
 *   
 * @author alex.bereznevatiy@gmail.com
 *
 */
public interface Token extends CharSequence {
	
	/**
	 * @param keyword
	 * @return <code>true</code> if this token equals to
	 * some keyword passed. Otherwise returns <code>false</code>.
	 */
	boolean equalsTo(CharSequence keyword);
	
	/**
	 * @param character
	 * @return <code>true</code> if this token equals to single character.
	 * Otherwise returns <code>false</code>.
	 */
	boolean equalsTo(char c);
	
	/**
	 * @return <code>true</code> if this token is java word.
	 */
	boolean isWord();
	
	/**
	 * @return <code>true</code> if this token is digit.
	 */
	boolean isDigitLiteral();
	
	/**
	 * @return <code>true</code> if this token is string literal
	 */
	boolean isStringLiteral();
	
	/**
	 * @return <code>true</code> if this token is character literal
	 */
	boolean isCharacterLiteral();
	
	/**
	 * @return <code>true</code> if this token is single- or multi-line comment
	 */
	boolean isComment();
	
	/**
	 * Replaces this token with other sequence.
	 * In case sequence is <code>null</code> or empty this token will be 
	 * ignored when flushing result class.
	 * 
	 * @param replacement
	 */
	void replace(CharSequence replacement);
	
	/**
	 * @return line first character of this token belong to.
	 */
	int getLine();
	
	/**
	 * @return offset of first character of this token relative to the beginning of the line.
	 */
	int getOffset();

	/**
	 * Writes characters of this token to the result.
	 * @param result
	 */
	void writeTo(StringBuilder result);
	
	/**
	 * @return modifiable raw content of the token
	 */
	StringBuilder getRaw();
	
	/**
	 * @return next token in the chain or <code>null</code> if there is no next token.
	 */
	Token next();
}
